fn sum(n1: i32, n2: i32) -> i32 {
    let mut m = 0;

    // 不可变闭包
    let closure = |n: i32| n * 100;

    // 可变闭包，捕获并修改 `m`
    let mut inner = |v: i32| {
        m += v; // 修改 m 的值
    };

    inner(10);
    println!("{}", m);

    return closure(n1) + n2;
}

fn main() {
    let result = sum(50, 25);
    println!("50 + 25 = {}", result);
    let mut x = 10;
    // 可变
    let mut fns = |a| { x += a };
    fns(5);
    println!("X1 = {}", x);
    let name = String::from("Iceman");
    // move将外部变量转移到闭包内
    let log = move |msg| {
        println!("{} - {}", name, msg);
    };
    log("Hello");
    // 报错 name已经被闭包借用
    //println!("name = {}", name);
}
